set(LIB_NAME ossim_gdal_plugin)
MESSAGE( "************** LIBRARY SETUP FOR ossim_gdal_plugin ******************")

# Include ossim cmake stuff:
include(OssimVersion)
include(OssimCommonVariables)
include(OssimUtilities)

SET(OSSIM_FRAMEWORK_GENERATION "OFF")
SET(OSSIM_USER_DEFINED_DYNAMIC_OR_STATIC "SHARED")

find_package(TIFF)
find_package(ZLIB)
find_package(GDAL)
find_package(CURL)
find_package(EXPAT)
find_library(SQLITE_LIBRARY NAMES sqlite sqlite3)
find_library(PROJ4_LIBRARY NAMES proj proj4)

# OSSIM - Required: 
find_package(ossim)
if(OSSIM_FOUND)
   include_directories( ${OSSIM_INCLUDE_DIR} )
   set( requiredLibs ${requiredLibs} ${OSSIM_LIBRARIES} )
else(OSSIM_FOUND)
   message(FATAL_ERROR "Could not find ossim")
endif(OSSIM_FOUND)


MESSAGE( STATUS "GDAL_LIBRARY        = ${GDAL_LIBRARY}" )
MESSAGE( STATUS "GDAL_INCLUDE        = ${GDAL_INCLUDE_DIR}" )
MESSAGE( STATUS "TIFF_LIBRARY        = ${TIFF_LIBRARY}" )
MESSAGE( STATUS "TIFF_INCLUDE        = ${TIFF_INCLUDE_DIR}" )
MESSAGE( STATUS "EXPAT_LIBRARY       = ${EXPAT_LIBRARY}" )
MESSAGE( STATUS "SQLITE_LIBRARY      = ${SQLITE_LIBRARY}" )
MESSAGE( STATUS "PROJ4_LIBRARY       = ${PROJ4_LIBRARY}" )

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${GDAL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${GEOTIFF_INCLUDE_DIR})

IF(NOT SQLITE_LIBRARY)
   SET(SQLITE_LIBRARY "")
ENDIF(NOT SQLITE_LIBRARY)

IF(NOT PROJ4_LIBRARY)
   SET(PROJ4_LIBRARY "")
ENDIF(NOT PROJ4_LIBRARY)

IF(NOT CURL_FOUND)
   SET(CURL_LIBRARY "")
ENDIF(NOT CURL_FOUND)

IF(NOT EXPAT_FOUND)
   SET(EXPAT_LIBRARY "")
ENDIF(NOT EXPAT_FOUND)

FILE(GLOB_RECURSE OSSIMPLUGIN_SRCS *.cpp)
FILE(GLOB_RECURSE OSSIMPLUGIN_HEADERS *.h)

####
# OSSIMPLUGINSMAKINGDLL controls dll linkage on windows.  
# Adding this sets OSSIM_PLUGINS_DLL #define TO "__declspec(dllexport)".
###
add_definitions("-DOSSIMPLUGINSMAKINGDLL")

# Adjust the install library path:
if(OSSIM_INSTALL_PLUGINS_WITH_VERSION)
   set(INSTALL_LIBRARY_DIR   "${INSTALL_LIBRARY_DIR}/ossim-${OSSIM_VERSION}/plugins")
else(OSSIM_INSTALL_PLUGINS_WITH_VERSION)
   set(INSTALL_LIBRARY_DIR   "${INSTALL_LIBRARY_DIR}/ossim/plugins")
endif(OSSIM_INSTALL_PLUGINS_WITH_VERSION)
if(WIN32)
 set(INSTALL_RUNTIME_DIR "${INSTALL_RUNTIME_DIR}/ossim/plugins")
endif()

OSSIM_LINK_LIBRARY(${LIB_NAME}
                   COMPONENT_NAME ossim TYPE "${OSSIM_PLUGIN_LINK_TYPE}"
		   LIBRARIES ${OSSIM_LIBRARIES} ${GDAL_LIBRARY} ${KAKADU_LIBRARY} ${KAKADU_AUX_LIBRARY}  ${KAKADU_ADDITIONAL_OBJS}  ${TIFF_LIBRARY} ${CURL_LIBRARY} ${PROJ4_LIBRARY} ${SQLITE_LIBRARY} ${EXPAT_LIBRARIES} ${ZLIB_LIBRARY} ${GEOTIFF_LIBRARY}
                   HEADERS "${OSSIMPLUGIN_HEADERS}"
		   SOURCE_FILES "${OSSIMPLUGIN_SRCS}"
                   INSTALL_LIB)

